package com.neuedu.oop;

public class Rectangle {
    /**
     * 矩形左上角顶点坐标
     */
    Point point;
    /**
     * 矩形的宽
     */
    int width;
    /**
     * 矩形的高
     */
    int height;

    public Rectangle(Point point, int width, int height) {
        this.point = point;
        this.width = width;
        this.height = height;
    }

    /**
     *
     * @param rect 另一个矩形
     * @return 这个矩形与另一个矩形是否相交
     */
    public String intersect(Rectangle rect){
        return (Math.abs((Math.abs(rect.point.x)+rect.width)/2
                -(this.point.x+this.width)/2)<(this.width+rect.width)/2)
                &&(Math.abs((Math.abs(rect.point.y)+rect.height)/2
                -(this.point.y)+this.height)/2<(this.height+ rect.height)/2)?"相交":"相离";
    }

    public static void main(String[] args) {
        Rectangle r=new Rectangle(new Point(20,5),3,4);
        Rectangle r1=new Rectangle(new Point(1,10),30,40);
        System.out.println(r.intersect(r1));
    }

}
